package com.quxing.amazon.security;

import com.quxing.amazon.common.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.quxing.amazon.common.StatusConst.TOKEN_EXPIRE_CODE;
import static com.quxing.amazon.common.StatusConst.UNAUTHORIZED;


/**
 * @author zhb
 * @description 未登录处理
 * @date 2020/11/27 16:50
 */
@Component
public class JwtAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.writeError(response,TOKEN_EXPIRE_CODE, UNAUTHORIZED);
    }
}
